#include "main.h"

extern TIM_HandleTypeDef htim9;

inline void Buzzer_Start(buzzer_tone_t tone, uint8_t* state)
{
    __HAL_TIM_SetAutoreload(&htim9, 1000000 / tone);
    __HAL_TIM_SetCompare(&htim9, TIM_CHANNEL_2, tone/2);
    if(HAL_TIM_PWM_Start(&htim9, TIM_CHANNEL_2) == HAL_OK)
        *state = 1;
}

inline void Buzzer_Stop(uint8_t* state)
{
    if(HAL_TIM_PWM_Stop(&htim9, TIM_CHANNEL_2) == HAL_OK)
        *state = 0;
}